package com.baiyun.proceduce;

import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.ResultSet;

import com.baiyun.tools.ConnDB;

public class TestWithRS {


	public static void main(String[] args) {
	
        try {
            // 1.加载驱动
            // 2.得到连接
            Connection ct = ConnDB.getConnection();
            // 3.创建CallableStatement
            CallableStatement cs = ct.prepareCall("{call sp_stu(?,?)}");
            //给第一个?赋值
            cs.setString(1,"计算机");
            //给第二个?赋值
            cs.registerOutParameter(2,oracle.jdbc.OracleTypes.CURSOR);
            //4、执行
            cs.execute();
            //得到结果集
            ResultSet rs = (ResultSet) cs.getObject(2);
            while (rs.next()) {
                System.out.println(rs.getInt(1) + " " + rs.getString(2));
            }
            //5、关闭
            rs.close();
            cs.close();
            ct.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
	}

}
